home *** CD-ROM | disk | FTP | other *** search
/ Amiga CD-Sensation: Golden Games / Amiga CD-Sensation - Ausgabe 2 - Golden Games (1996)(GTI - Schatztruhe)(DE)[!].iso / Various / ShuffleRun / Sources / Joystick.c < prev    next >
C/C++ Source or Header  |  1993-02-13  |  2KB  |  63 lines

  1. /* Joystick()                                                          */
  2. /* Joystick() is a handy, easy and fast but naughty function that hits */
  3. /* the hardware of the Amiga. It looks at either port 1 or port 2, and */
  4. /* returns a bitfield containing the position of the stick and the     */
  5. /* present state of the button.                        */
  6. /*                                       */
  7. /* Synopsis: value = Joystick( port );                                 */
  8. /* value:    (UBYTE) If the fire button is pressed, the first bit is   */
  9. /*         set. If the stick is moved to the right, the second bit   */
  10. /*         is set, and if the stick is moved to the left, the third  */
  11. /*         bit is set. The fourth bit is set if the stick is moved   */
  12. /*         down, and the fifth bit is set if the stick is moved up.  */
  13. /* port:     (UBYTE) Set the flag PORT1 if you want to check the first */
  14. /*         (mouse) port, or set the flag PORT2 if you want to check  */
  15. /*         the second (joystick) port.                               */
  16.  
  17. #include <hardware/custom.h>
  18. #include <hardware/cia.h>
  19.  
  20. #define CIAAPRA 0xBFE001
  21.  
  22. #define FIRE   1
  23. #define RIGHT  2
  24. #define LEFT   4
  25. #define DOWN   8
  26. #define UP    16
  27.  
  28. #define PORT1 1
  29. #define PORT2 2
  30.  
  31. extern __far struct Custom custom;
  32. struct CIA *cia = (struct CIA *) CIAAPRA;
  33.  
  34. UBYTE Joystick();
  35.  
  36.  
  37. UBYTE Joystick( port )
  38. UBYTE port;
  39. {
  40.   UBYTE data = 0;
  41.   UWORD joy;
  42.  
  43.   if( port == PORT1 )
  44.   {
  45.     /* PORT 1 ("MOUSE PORT") */
  46.     joy = custom.joy0dat;
  47.     data += !( cia->ciapra & 0x0040 ) ? FIRE : 0;
  48.   }
  49.   else
  50.   {
  51.     /* PORT 2 ("JOYSTICK PORT") */
  52.     joy = custom.joy1dat;
  53.     data += !( cia->ciapra & 0x0080 ) ? FIRE : 0;
  54.   }
  55.  
  56.   data += joy & 0x0002 ? RIGHT : 0;
  57.   data += joy & 0x0200 ? LEFT : 0;
  58.   data += (joy >> 1 ^ joy) & 0x0001 ? DOWN : 0;
  59.   data += (joy >> 1 ^ joy) & 0x0100 ? UP : 0;
  60.  
  61.   return( data );
  62. }
  63.